Skip to content

fix(expiry): rebuild pending-winnings reclaim with correct errors and TTL touches (Closes #397) - #464

Open
diahtech1 wants to merge 1 commit into
TevaLabs:mainfrom
diahtech1:fix/397-reclaim-expiry-errors
Open

fix(expiry): rebuild pending-winnings reclaim with correct errors and TTL touches (Closes #397)#464
diahtech1 wants to merge 1 commit into
TevaLabs:mainfrom
diahtech1:fix/397-reclaim-expiry-errors

Conversation

@diahtech1

@diahtech1 diahtech1 commented Aug 26, 2026

Copy link
Copy Markdown

Summary

Rebuilds reclaim_expired_pending_winnings with correct error semantics and TTL touch behavior. The error meanings were confused in recent diffs — tests expected NoActiveRound for conditions that should have distinct, descriptive errors.

What changed

Critical fix: error discriminant collision

PendingWinningsNotExpired shared discriminant 66 with OracleTimestampOutsideWindow. Moved PendingWinningsNotExpired to 79 (next available slot) to resolve the collision.

Reclaim function (contracts/src/admin.rs)

  • Distinct errors returned for each failure path:
    • ExpiryNotConfigured (78) — expiry is disabled (value is 0 or absent)
    • PendingWinningsNotFound (77) — no pending winnings entry for the user
    • PendingWinningsNotExpired (79) — entry exists but has not yet reached the age threshold
  • TTL touches added on expiry key, pending winnings key, and updated-at key before reading them, consistent with get_pending_winnings behavior
  • Updated doc comment to accurately document the three error variants

Tests (contracts/src/tests/pending_winnings_expiry.rs)

  • Fixed test_reclaim_fails_when_expiry_disabled: NoActiveRoundExpiryNotConfigured
  • Fixed test_reclaim_fails_for_nonexistent_pending: NoActiveRoundPendingWinningsNotFound
  • New test_reclaim_fails_when_expiry_disabled_after_enable: enables expiry, disables it, verifies ExpiryNotConfigured
  • New test_reclaim_fails_for_premature_reclaim: tests age threshold at 200, 400, 499 (all PendingWinningsNotExpired), then 600 (succeeds)

Bindings (bindings/src/index.ts)

  • Fixed wrong discriminants: EpochBudgetExceeded (66→67), OracleNotLive (66→68), InvalidPayoutPolicy (67→69)
  • Added missing error codes: RotationDelayNotElapsed (55), OracleTimestampOutsideWindow (66), and all codes 70–79

Documentation (docs/WALLET_ERROR_GUIDE.md)

  • Added 14 missing error codes (55, 62–79) including the three reclaim errors
  • Fixed malformed table lines where entries were jammed together

Files changed

File Change
contracts/src/errors.rs PendingWinningsNotExpired 66 → 79
contracts/src/admin.rs TTL touches + updated doc comment
contracts/src/tests/pending_winnings_expiry.rs Fixed 2 tests, added 2 new tests
bindings/src/index.ts Fixed discriminants, added 14 error codes
docs/WALLET_ERROR_GUIDE.md Added missing codes, fixed table formatting

Acceptance criteria

… TTL touches (Closes TevaLabs#397)

Fix error semantics for reclaim_expired_pending_winnings that were
confused in recent diffs. The function now returns three distinct errors:

- ExpiryNotConfigured (78) when pending winnings expiry is disabled (0)
- PendingWinningsNotFound (77) when no entry exists for the user
- PendingWinningsNotExpired (79) when the entry has not yet reached
  the configured age threshold

Also fixes a critical error discriminant collision where
PendingWinningsNotExpired shared value 66 with OracleTimestampOutsideWindow.
PendingWinningsNotExpired is now 79.

Changes:
- contracts/src/errors.rs: move PendingWinningsNotExpired from 66 to 79
- contracts/src/admin.rs: add _extend_persistent_ttl on expiry key,
  pending winnings key, and updated-at key before reading them; update
  doc comment to document the three distinct errors
- contracts/src/tests/pending_winnings_expiry.rs: fix wrong error
  expectations (NoActiveRound -> ExpiryNotConfigured/PendingWinningsNotFound),
  add test_reclaim_fails_when_expiry_disabled_after_enable and
  test_reclaim_fails_for_premature_reclaim
- bindings/src/index.ts: fix wrong discriminants for EpochBudgetExceeded,
  OracleNotLive, InvalidPayoutPolicy; add RotationDelayNotElapsed,
  OracleTimestampOutsideWindow, and all missing error codes 70-79
- docs/WALLET_ERROR_GUIDE.md: add 14 missing error codes (55, 62-79),
  fix malformed table lines

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rebuild: pending-winnings expiry reclaim with precise errors

1 participant